# 观察者模式
class Observer:
    def __init__(self, strname, strsub):
        self.name = strname
        self.sub = strsub

    def Update(self):
        pass


class StockObserver(Observer):
    def Update(self):
        print("%s:%s, Stop watching Stock and go on work!" % (self.name, self.sub.action))


class MBAObserver(Observer):
    def Update(self):
        print("%s:%s, Stop watching NBA and go on work!" % (self.name, self.sub.action))


class SecretaryBase:
    def __init__(self):
        self.observer = []

    def Attach(self, new_observer):
        pass

    def Notify(self):
        pass


class Secretary(SecretaryBase):
    def Attach(self, new_observer):
        self.observer.append(new_observer)

    def Notify(self):
        for p in self.observer:
            p.Update()


if __name__ == "__main__":
    p = Secretary()
    s1 = StockObserver("xh", p)
    s2 = MBAObserver("wyt", p)
    p.Attach(s1)
    p.Attach(s1)
    p.action = "Waring:Boos"
    p.Notify()
